import json

import requests_html
from requests_html import HTMLSession

session = HTMLSession()


def get_html(uri):
    r = session.get(uri)
    html: requests_html.HTML = r.html
    return html


def get_info(url):
    html = get_html(url)
    issue_span = html.find("span .Counter", first=True)
    if issue_span is None:
        issue_number = 0
    else:
        issue_number = issue_span.text

    # commit_number = html.find('.commits', first=True).find('span').text
    # print(html.search('.commits'))
    print("issue = %s " % issue_number)


def get_star_list(page: str):
    html = get_html(
        "https://github.com/search?l=&p=" + page + "&q=stars%3A%3E1000&ref=advsearch&type=Repositories&utf8=%E2%9C%93")
    repo_list = html.find(".repo-list-item")
    for item in repo_list:
        s = item.find("a", first=True).attrs.get('data-hydro-click')
        url = json.loads(s)['payload']['result']['url']
        print("url = %s" % url)
        get_info(url)


get_star_list(str(1))
